<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>添加订单</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
        content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="../static/TG_logo.jpg" type="image/x-icon" />
    <link rel="stylesheet" href="../static/css/font.css">
    <link rel="stylesheet" href="../static/css/xadmin.css">
    <script src="../js/jquery.min.js"></script>
    <script type="text/javascript" src="../static/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="../static/js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>
    <div class="x-body">
        <form class="layui-form">
            <div class="layui-form-item">
                <label for="cid" class="layui-form-label">
                    <span class="x-red">*</span>商品编号
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="cid" name="cid" required lay-verify="required" autocomplete="off"
                        class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label for="username" class="layui-form-label">
                    <span class="x-red">*</span>买家
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="buyername" name="buyername" required lay-verify="required" autocomplete="off"
                        class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red">*</span>卖家
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="sellername" name="sellername" required lay-verify="required" autocomplete="off"
                        class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label for=" quantity" class="layui-form-label">
                    <span class="x-red">*</span>交易数量
                </label>
                <div class="layui-input-inline">
                    <input type="text" id=" quantity" name=" quantity" required lay-verify="number" autocomplete="off"
                        class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red">*</span>应付金额
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="total_price" name="price" required lay-verify="price" autocomplete="off"
                        class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label for="username" class="layui-form-label">
                    <span class="x-red">*</span>订单状态
                </label>
                <div class="layui-input-inline">
                    <select name="contrller">
                        <option value="">订单状态</option>
                        <option value="0">待确认</option>
                        <option value="1">已确认</option>
                        <option value="2">已收货</option>
                        <option value="3">已取消</option>
                        <option value="4">已完成</option>
                        <option value="5">已作废</option>
                    </select>
                </div>
                
                <div class="layui-form-item">
                    <label for="L_repass" class="layui-form-label">
                    </label>
                    <button class="layui-btn" lay-filter="add" lay-submit="" onclick="add_order()">
                        增加
                    </button>
                </div>
        </form>
    </div>

</body>
    
<script>
  function add_order() {
            var cid = $("#cid").val();
            var buyername = $("#buyername").val();
            var phone = $("#phone").val();
            var quantity = $("#quantity").val();
            var total_price = $("#total_price").val();
            var sort = $("#contrller").val();
            var params = {
                "cid": cid,
                "buyername": buyername,
                "sellername": sellername,
                "quantity": quantity,
                "total_price":total_price,
                "sort":sort,

            }
            console.log(params);
            //发异步，把数据提交给后端
            $.ajax({
                type: 'post',
                url: 'http://127.0.0.1:8000/v1/TGadmin/order/'+user,
                data: JSON.stringify(params),
                dataType: 'json',
                contentType: 'application/json',
                beforeSend: function (request) {
                    request.setRequestHeader("authorization", localStorage.getItem('TGshop_token'))
                },
                success: function (data) {
                    console.log(data);
                    if (data.code == 200) {
                        layer.alert("增加成功", { icon: 6 }, function () {
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                        })
                    } else {
                        alert('添加失败!')
                    }
                }
            })
        }
</script>

</html>